package tomkitty.server;

import tomkitty.turdlet.*;
import tomkitty.util.*;
import java.util.*;
import java.net.*;

public class HttpRequest {

	public class Header {

		public String method;
		public String version;
		public URI uri;

		public Header(String method, String version, URI uri) {
			this.method = method;
			this.version = version;
			this.uri = uri;
		}

	}

	private Header header = null;
	private String body = "";
	private boolean valid = true;

	public Header getHeader() {
		return header;
	}

	public String getBody() {
		return body;
	}

	public boolean isValid() {
		return valid;
	}

	public HttpRequest(String reqLine, String body) {

		HttpRequestParser p = new HttpRequestParser(reqLine);

		String method = "";
		String version = "";
		URI uri = null;

		if (! p.isValid()) {
			valid = false;
		} else {
			try {
				method = p.getMethod();
				version = p.getVersion();
				uri = new URI(p.getURI());
			} catch (Exception e) {
				valid = false;
			}
		}

		if (valid) {
			this.header = new Header(method, version, uri);
			this.body = body;
		}

	}

}


